import confirmModal from './index.vue'
import { createVNode, render } from 'vue'
const divDom = document.createElement('div')
divDom.setAttribute('class', 'modal-container')
document.body.appendChild(divDom);
const modalPlguin = (option) => {
  return new Promise((resolve, reject) => {
    const handleModalOk = () => {//确认
      resolve('ok')
      setTimeout(() => {
        render(null, divDom)
      }, 200)
    }
    const handleModalCancel = () => {//  取消
      reject('cancel')
      render(null, divDom)
    }
    const vNode = createVNode(confirmModal, { ...option, handleModalOk, handleModalCancel })
    render(vNode, divDom)
  })
}

export default {
  install(app) {
    app.config.globalProperties.$confirmModal = modalPlguin
  }
}